#include "ControlledObject.h"
#include "Renderer.h"

namespace Nezha
{

	void ControlledObject::updateController(float dt)
	{
		if(mController)
		{
			mController->update(dt);
		}
	}

	void ControlledObject::postUpdateController(float dt)
	{
		if(mController)
		{
			mController->postUpdate(dt);
		}
	}

	void ControlledObject::attachController(Controller* c)
	{
		if(mController != c)
		{
			if(mController)
			{
				mController->attachTargetObject(this);
			}
		}
	}

	void ControlledObject::detachController()
	{
		if(mController)
		{
			mController->detachTarget();
			mController = NULL;
		}
	}

	void Controller::attachTargetObject(ControlledObject* target)
	{
		if(target && mTargetObject.get() != target)
		{
			mTargetObject = target;
		}
	}

	void Controller::detachTarget()
	{
		mTargetObject = NULL;
	}

}//end namespace Nezha